<template>
  <div class="dialog-container">
    <el-dialog
      title="批量修改排口因子配置"
      :visible="dialogVisible"
      @open="initData"
      @close="closeDialog"
    >
      <el-form
        ref="form"
        :model="dataForm"
        class="dialog-form"
        :rules="rules"
        label-width="110px"
        size="mini"
      >
        <template>
          <el-row>
            <el-col :span="12">
              <el-form-item label="恒值报警时限（分钟）" prop="constantTime">
                <el-input-number v-model="dataForm.constantTime" placeholder="请输入恒值报警时限（分钟）" />
              </el-form-item>
            </el-col>
          </el-row>
        </template>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="saveLoading" class="sure-btn" size="mini" type="primary" @click="handleSave">保存</el-button>
        <el-button size="mini" class="cancel-btn" @click="closeDialog">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { editBatch } from '@/api/base/outletsFactor'

export default {
  name: 'UpDialog',
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    outletId: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      saveLoading: false,
      dataForm: {
        outletId: null,
        constantTime: null
      },
      rules: {
        // examineResult: [{ required: true, message: '请选择违法行为判定', trigger: 'change' }]
      }
    }
  },
  created() {
  },
  methods: {
    initData() {
      this.saveLoading = false
      if (this.outletId) {
        this.dataForm.outletId = this.outletId
      }
    },
    handleSave() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.saveLoading = true
          if (this.dataForm) {
            editBatch(this.dataForm).then(() => {
              this.$message({
                type: 'success',
                message: '修改成功'
              })
              this.$emit('flushPage')
              this.$emit('closeDialog')
              this.clearData()
              this.saveLoading = false
            }).catch(() => {
              this.saveLoading = false
            })
          }
        }
      })
    },
    closeDialog() {
      this.$emit('closeDialog')
      this.clearData()
      this.$refs['form'].clearValidate()
    },
    clearData() {
      this.dataForm = {
        outletId: null,
        constantTime: null
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
